﻿using System;
using System.Collections.Generic;
using System.Text;
using NLBS.Framework;
using NLBS.Entity;

namespace NLBS.Data.Business
{
   public class WordFilterData
    {
       private static readonly string WordFilterKey = "WordFilterKey";
       private static List<WordFilter> GetWordFilter()
       {
           ContentCache cache = ContentCache.Instantiate();
           List<WordFilter> lists = (List<WordFilter>)cache[WordFilterKey];
           if (lists == null)
           {
               lists = new List<WordFilter>(DbProvider.Instance().GetWordFilter());
               if (lists != null)
               {
                   cache.Insert(WordFilterKey, lists, CacheDuration.Long);
               }
           }
           return lists;
       }

       public static List<WordFilter> WordFilter
       {
           get
           {
               return GetWordFilter();
           }
       }

       public static WordFilter GetWordFilterByID(int id)
       {
           return WordFilter.Find(delegate(WordFilter w)
            {
                return w.WordFilterID == id;
            });
       }
       public static void InsertWordFilter(WordFilter wf)
       {
           int result = DbProvider.Instance().InsertWordFilter(wf);
           wf.WordFilterID = result;
           WordFilter.Insert(0, wf);
           //WordFilter.TrimExcess();
       }

       public static void UpdateWordFilter(WordFilter wf)
       {
           DbProvider.Instance().UpdateWordFilter(wf);
           //WordFilter oldWf = GetWordFilterByID(wf.WordFilterID);
           //IList<WordFilter> list = GetWordFilter();
           //list[list.IndexOf(oldWf)] = wf;
       }

       public static void DeleteWordFilter(int wfID)
       {
           DbProvider.Instance().DeleteWordFilter(wfID);
           WordFilter.Remove(GetWordFilterByID(wfID));
       }
    }
}
